cc.Class({
  extends: cc.Component,
  properties: {
    levelMapPanel: cc.Node,
    shareBtnNode: cc.Node
  },
  onLoad: function () {
    cc.MainUI = this;
  },
  start: function () {
    this.isLookAd = false;
    console.log("  Start Main ");
    cc.pvz.PlayerData.checkAndResetGameDate();
    cc.pvz.PlayerData.checkAndResetAdData();
    cc.pvz.PlayerData.checkAndResetShare();
    this.initMainUI();
  },
  initMainUI: function () {
    this.stageLevel = cc.pvz.PlayerData.getStageLevel();
    this.curStageLevel = this.stageLevel;
    this.refreshLevelMapShow(this.stageLevel);
    this.refreshLevelEnemyShow(this.stageLevel);
    this.refreshLevelPlayerShow();
    this.refreshPageBtnShow();
    cc.pvz.TAUtils.trackAdUIShow(cc.pvz.GameConfig.AdType.关卡扫荡);
  },
  refreshLevelMapShow: function () {},
  refreshLevelPlayerShow: function () {},
  refreshLevelEnemyShow: function () {},
  refreshPageBtnShow: function () {
    if (1 == this.curStageLevel) {
      this.onCheckPageBtnRedTip(false);
    } else if (this.curStageLevel == cc.pvz.GameConfig.MaxLevel || this.curStageLevel - this.stageLevel == 2) {
      this.onCheckPageBtnRedTip(true);
    } else {
      this.onCheckPageBtnRedTip(true);
      this.onCheckPageBtnRedTip(false);
    }
  },
  onCheckPageBtnRedTip: function (e) {
    if (e) {
      for (var t = this.curStageLevel - 1; t > 0; t--) {
        var i = this.stageLevel > t;
        var o = cc.pvz.PlayerData.getLevelBoxData(t);
        for (var a = 0; a < o.length; a++) {
          if (0 == o[a] && i) {
            return;
          }
        }
      }
    } else {
      for (var c = this.curStageLevel + 1; c <= this.stageLevel; c++) {
        var s = this.stageLevel > c;
        var n = cc.pvz.PlayerData.getLevelBoxData(c);
        for (var r = 0; r < n.length; r++) {
          if (0 == n[r] && s) {
            return;
          }
        }
      }
    }
  },
  showMainUI: function () {
    this.node.active = true;
    cc.pvz.utils.fadeInBtn(this.node);
    this.stageLevel = cc.pvz.PlayerData.getStageLevel();
    this.curStageLevel = this.stageLevel;
    this.refreshLevelMapShow(this.stageLevel);
    this.refreshLevelEnemyShow(this.stageLevel);
    this.refreshPageBtnShow();
    cc.pvz.TAUtils.trackAdUIShow(cc.pvz.GameConfig.AdType.关卡扫荡);
    this.setClubBtnVisible(true);
    cc.RedControl.onCheckMissionRed();
    cc.UITool && cc.UITool.isChangeArray && this.refreshLevelPlayerShow();
  },
  onHideLvBoxPanel: function () {},
  hideMainUI: function () {
    this.onHideLvBoxPanel();
    this.node.active = false;
    this.setClubBtnVisible(false);
  },
  setClubBtnVisible: function () {},
  onPopup1st: function () {
    this.onHideLvBoxPanel();
    this.setClubBtnVisible(false);
  },
  onAllClosed: function () {
    this.node.active && this.setClubBtnVisible(true);
  },
  onClickStagePage: function (e, t) {
    if (!this.isLookAd) {
      if (parseInt(t) < 0) {
        this.curStageLevel--;
      } else {
        this.curStageLevel++;
      }
      this.refreshLevelMapShow(this.curStageLevel);
      this.refreshLevelEnemyShow(this.curStageLevel);
      this.refreshPageBtnShow();
    }
  },
  onClickSet: function () {
    this.isLookAd || cc.popupManager.popup("mainUI", "set", "UISet", {
      ad: false,
      scale: true
    }, 0);
  },
  onClickSign: function () {
    this.isLookAd || cc.popupManager.popup("mainUI", "signUI", "UISign", {
      ad: false,
      scale: true
    });
  },
  onClickTask: function () {
    this.isLookAd || cc.popupManager.popup("mainUI", "TaskUI", "UITask", {
      ad: false,
      scale: false
    });
  },
  onClickFund: function () {
    this.isLookAd || cc.popupManager.popup("mainUI", "FundUI", "UIFund", {
      ad: false,
      scale: false
    });
  },
  onClickOther: function () {
    this.onHideLvBoxPanel();
    cc.popupManager.showToast("暂未开启");
  },
  onClickShareUI: function () {
    cc.popupManager.popup("mainUI", "FenxiangUI", "UIShare", {
      ad: false,
      scale: true
    });
  },
  onClickRankMode: function () {
    cc.popupManager.popup("mainUI", "Rank", "UIRankMode", {
      ad: false,
      scale: false
    }, this.node);
  },
  enterGame2: function () {
    cc.assetManager.loadBundle("game2", function (e, t) {
      if (t) {
        cc.director.loadScene("game2");
        cc.player.game2t = Date.now();
      }
    });
  },
  onClickGame2: function () {
    var e = cc.player.game2t || -1;
    if (Date.now() - e < 18e5) {
      cc.popupManager.popup("mainUI", "ModeTipUI", "UIAdGame2", {
        ad: false,
        scale: false
      }, this);
    } else {
      this.enterGame2();
    }
  },
  onClickGame1: function () {
    if (!cc.MainUI.isLookAd) {
      if (cc.pvz.PlayerData.isEnoughArrayTool()) {
        if (cc.pvz.PlayerData.getPower() < cc.pvz.GameConfig.BattlePower) {
          if (cc.pvz.PlayerData.isHaveBuyPowerTimes()) {
            cc.popupManager.popup("mainUI", "powerbuy", "UIPowerBuy", {
              ad: false,
              scale: true
            }, cc.pvz.GameConfig.UIFromType.主界面);
          } else {
            cc.popupManager.showToast("体力不足");
          }
        } else {
          cc.pvz.PlayerData.usePlayerPower(-cc.pvz.GameConfig.BattlePower);
          cc.MainControl.checkPowerInfo();
          cc.pvz.PlayerData.addMissionProgress(cc.pvz.GameConfig.MissionType.挑战主线章节1次, 1);
          cc.MainUI.setClubBtnVisible(false);
          cc.pvz.runtimeData.init(0, this.stageLevel);
          cc.director.loadScene("game1");
          cc.pvz.TAUtils.trackBackpack(this.stageLevel);
        }
      } else {
        cc.popupManager.showToast("还有未上阵的卡皮巴拉！");
      }
    }
  }
});